package com.yserp.rlzy_gz.service.impl;
import com.yserp.rlzy_gz.service.TPayServiceI;
import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
import com.yserp.rlzy_gz.entity.TPayEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.io.Serializable;
import org.jeecgframework.core.util.ApplicationContextUtil;
import org.jeecgframework.core.util.MyClassLoader;
import org.jeecgframework.core.util.StringUtil;
import org.jeecgframework.web.cgform.enhance.CgformEnhanceJavaInter;

@Service("tPayService")
@Transactional
public class TPayServiceImpl extends CommonServiceImpl implements TPayServiceI {

	
 	public void delete(TPayEntity entity) throws Exception{
 		super.delete(entity);
 		//执行删除操作增强业务
		this.doDelBus(entity);
 	}
 	
 	public Serializable save(TPayEntity entity) throws Exception{
 		Serializable t = super.save(entity);
 		//执行新增操作增强业务
 		this.doAddBus(entity);
 		return t;
 	}
 	
 	public void saveOrUpdate(TPayEntity entity) throws Exception{
 		super.saveOrUpdate(entity);
 		//执行更新操作增强业务
 		this.doUpdateBus(entity);
 	}
 	
 	/**
	 * 新增操作增强业务
	 * @param t
	 * @return
	 */
	private void doAddBus(TPayEntity t) throws Exception{
		//-----------------sql增强 start----------------------------
	 	//-----------------sql增强 end------------------------------
	 	
	 	//-----------------java增强 start---------------------------
	 	//-----------------java增强 end-----------------------------
 	}
 	/**
	 * 更新操作增强业务
	 * @param t
	 * @return
	 */
	private void doUpdateBus(TPayEntity t) throws Exception{
		//-----------------sql增强 start----------------------------
	 	//-----------------sql增强 end------------------------------
	 	
	 	//-----------------java增强 start---------------------------
	 	//-----------------java增强 end-----------------------------
 	}
 	/**
	 * 删除操作增强业务
	 * @param id
	 * @return
	 */
	private void doDelBus(TPayEntity t) throws Exception{
	    //-----------------sql增强 start----------------------------
	 	//-----------------sql增强 end------------------------------
	 	
	 	//-----------------java增强 start---------------------------
	 	//-----------------java增强 end-----------------------------
 	}
 	
 	private Map<String,Object> populationMap(TPayEntity t){
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("id", t.getId());
		map.put("create_name", t.getCreateName());
		map.put("create_by", t.getCreateBy());
		map.put("create_date", t.getCreateDate());
		map.put("update_name", t.getUpdateName());
		map.put("update_by", t.getUpdateBy());
		map.put("update_date", t.getUpdateDate());
		map.put("sys_org_code", t.getSysOrgCode());
		map.put("sys_company_code", t.getSysCompanyCode());
		map.put("bpm_status", t.getBpmStatus());
		map.put("gz_date", t.getGzDate());
		map.put("rz_num", t.getRzNum());
		map.put("person", t.getPerson());
		map.put("xdgz_pay", t.getXdgzPay());
		map.put("zxjt_pay", t.getZxjtPay());
		map.put("gl_pay", t.getGlPay());
		map.put("gwjt_pay", t.getGwjtPay());
		map.put("rcjt_pay", t.getRcjtPay());
		map.put("month_bonus", t.getMonthBonus());
		map.put("bf_wage", t.getBfWage());
		map.put("yf_total", t.getYfTotal());
		map.put("qkuan", t.getQkuan());
		map.put("old_insu", t.getOldInsu());
		map.put("yl_insu", t.getYlInsu());
		map.put("gjj", t.getGjj());
		map.put("qynj", t.getQynj());
		map.put("gsui", t.getGsui());
		map.put("dhf", t.getDhf());
		map.put("sdf", t.getSdf());
		map.put("fwf", t.getFwf());
		map.put("sf_total", t.getSfTotal());
		return map;
	}
 	
 	/**
	 * 替换sql中的变量
	 * @param sql
	 * @param t
	 * @return
	 */
 	public String replaceVal(String sql,TPayEntity t){
 		sql  = sql.replace("#{id}",String.valueOf(t.getId()));
 		sql  = sql.replace("#{create_name}",String.valueOf(t.getCreateName()));
 		sql  = sql.replace("#{create_by}",String.valueOf(t.getCreateBy()));
 		sql  = sql.replace("#{create_date}",String.valueOf(t.getCreateDate()));
 		sql  = sql.replace("#{update_name}",String.valueOf(t.getUpdateName()));
 		sql  = sql.replace("#{update_by}",String.valueOf(t.getUpdateBy()));
 		sql  = sql.replace("#{update_date}",String.valueOf(t.getUpdateDate()));
 		sql  = sql.replace("#{sys_org_code}",String.valueOf(t.getSysOrgCode()));
 		sql  = sql.replace("#{sys_company_code}",String.valueOf(t.getSysCompanyCode()));
 		sql  = sql.replace("#{bpm_status}",String.valueOf(t.getBpmStatus()));
 		sql  = sql.replace("#{gz_date}",String.valueOf(t.getGzDate()));
 		sql  = sql.replace("#{rz_num}",String.valueOf(t.getRzNum()));
 		sql  = sql.replace("#{person}",String.valueOf(t.getPerson()));
 		sql  = sql.replace("#{xdgz_pay}",String.valueOf(t.getXdgzPay()));
 		sql  = sql.replace("#{zxjt_pay}",String.valueOf(t.getZxjtPay()));
 		sql  = sql.replace("#{gl_pay}",String.valueOf(t.getGlPay()));
 		sql  = sql.replace("#{gwjt_pay}",String.valueOf(t.getGwjtPay()));
 		sql  = sql.replace("#{rcjt_pay}",String.valueOf(t.getRcjtPay()));
 		sql  = sql.replace("#{month_bonus}",String.valueOf(t.getMonthBonus()));
 		sql  = sql.replace("#{bf_wage}",String.valueOf(t.getBfWage()));
 		sql  = sql.replace("#{yf_total}",String.valueOf(t.getYfTotal()));
 		sql  = sql.replace("#{qkuan}",String.valueOf(t.getQkuan()));
 		sql  = sql.replace("#{old_insu}",String.valueOf(t.getOldInsu()));
 		sql  = sql.replace("#{yl_insu}",String.valueOf(t.getYlInsu()));
 		sql  = sql.replace("#{gjj}",String.valueOf(t.getGjj()));
 		sql  = sql.replace("#{qynj}",String.valueOf(t.getQynj()));
 		sql  = sql.replace("#{gsui}",String.valueOf(t.getGsui()));
 		sql  = sql.replace("#{dhf}",String.valueOf(t.getDhf()));
 		sql  = sql.replace("#{sdf}",String.valueOf(t.getSdf()));
 		sql  = sql.replace("#{fwf}",String.valueOf(t.getFwf()));
 		sql  = sql.replace("#{sf_total}",String.valueOf(t.getSfTotal()));
 		sql  = sql.replace("#{UUID}",UUID.randomUUID().toString());
 		return sql;
 	}
 	
 	/**
	 * 执行JAVA增强
	 */
 	private void executeJavaExtend(String cgJavaType,String cgJavaValue,Map<String,Object> data) throws Exception {
 		if(StringUtil.isNotEmpty(cgJavaValue)){
			Object obj = null;
			try {
				if("class".equals(cgJavaType)){
					//因新增时已经校验了实例化是否可以成功，所以这块就不需要再做一次判断
					obj = MyClassLoader.getClassByScn(cgJavaValue).newInstance();
				}else if("spring".equals(cgJavaType)){
					obj = ApplicationContextUtil.getContext().getBean(cgJavaValue);
				}
				if(obj instanceof CgformEnhanceJavaInter){
					CgformEnhanceJavaInter javaInter = (CgformEnhanceJavaInter) obj;
					javaInter.execute("t_pay",data);
				}
			} catch (Exception e) {
				e.printStackTrace();
				throw new Exception("执行JAVA增强出现异常！");
			} 
		}
 	}
}